//
//  UIBarButtonItem+Extension.swift
//  WKWeibo
//
//  Created by 恋guang年 on 16/3/28.
//  Copyright © 2016年 恋guang年. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    ///便利构造函数
    convenience init(imageName:String, target:AnyObject, action:Selector){
        let button = UIButton()
        button .setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button .setBackgroundImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        button.sizeToFit()
        self.init(customView: button)
    }
    ///  设置navigationBar
    class func setUPNavigationBarItem(imageName:String) -> UIBarButtonItem{
        //       设置导航栏左右按钮
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let heightImageName = imageName + "_highlighted"
        button.setBackgroundImage(UIImage(named:heightImageName), forState: UIControlState.Highlighted)
        button.sizeToFit()
        
        return  UIBarButtonItem(customView: button)
    }
}